<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>


 //promise.all()
//   function myall(proArr) {
//     return new Promise((resolve, reject) => {
//       let ret = []
//       let count = 0
//       let done = (i, data) => {
//         ret[i] = data
//         if(++count === proArr.length) resolve(ret)
//       }
//       for (let i = 0; i < proArr.length; i++) {
//         proArr[i].then(data => done(i,data) , reject)
//       }
//     })
//   }
   
   
// //promise.race();这么简单得益于promise的状态只能改变一次，即resolve和reject都只被能执行一次
//  function myrace(proArr) {
//     return new Promise(function (resolve, reject) {
//       for(let i=0;i<proArr.length;i++){
//         proArr[i].then(resolve,reject);
//       }
//     })
//   }
    function myPromise(arr){
      return new Promise((resolve,reject)=>{
        let count = 0;
        let newArr = []
        for(let i=0;i<arr.length;i++){
          arr[i].then(value=>{
            count++
            newArr[i] = value
            if(count === arr.length){
              return resolve(newArr)
            }
          },error=>{
            reject(error)
          })
        }
      })
    }

    function myrace(arr){
      return new Promise(function(resolve,reject){
        for(let i=0;i<arr.length;i++){
          arr[i].then(resolve,reject)
        }
      })
    }
  </script>
</body>
</html>